package com.shuoyue.ycgk.ui.papergroups.freedomnew;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.FreedomGroup;
import com.shuoyue.ycgk.entity.FreedomPaper;
import com.shuoyue.ycgk.entity.FreedomSet;
import com.shuoyue.ycgk.entity.QuestionParent;
import com.shuoyue.ycgk.entity.UserTestPaper;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface FreedomSetContract {
    interface View extends BaseView {

        void getFreedomPaperSuc(FreedomSet freedomPapers);

        void creataPaperSuc(Integer userTestPaper, String name,int type);

    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();


        public void getFreedomPaper(int modelId) {
            apply(model.getFreedomPaper(modelId))
                    .subscribe(new ApiSubscriber<Optional<FreedomSet>>(mView, this) {
                        @Override
                        public void onNext(Optional<FreedomSet> optional) {
                            super.onNext(optional);
                            mView.getFreedomPaperSuc(optional.getIncludeNull());
                        }

                    });
        }

        public void createFreedomPaper(int modelId, int type, String name) {
            apply(model.createFreedomPaper(modelId, type))
                    .subscribe(new ApiSubscriber<Optional<Integer>>(mView, this) {
                        @Override
                        public void onNext(Optional<Integer> optional) {
                            super.onNext(optional);
                            mView.creataPaperSuc(optional.getIncludeNull(), name,type);
                        }

                    });
        }

    }

    class Model extends BaseModel {
        Observable<BaseResult<Integer>> createFreedomPaper(int modelId, int type) {
            return RetrofitClient.getInstance().getApi().createFreedomPaper(modelId, type);
        }


        Observable<BaseResult<FreedomSet>> getFreedomPaper(int modelId) {
            return RetrofitClient.getInstance().getApi().getFreedomPaper(modelId);
        }
    }
}
